package cg.studio.algorithm.tree;


public class TreeRecursiveTraverse extends TreeAbstractTraverse
{
  public <T> void deepthTraverse( BinaryTree<T> root, DeepthTraverseOrder traverseOrder )
  {
    switch( traverseOrder )
    {
      case InOrder:
        inOrderTraverse( root );
        break;
      case PreOrder:
        preOrderTraverse( root );
        break;
      case PostOrder:
        postOrderTraverse( root );
        break;
    }
  }
  
  protected <T> void preOrderTraverse( BinaryTree<T> root )
  {
    root.display();
    if( root.getLeft() != null )
      inOrderTraverse( root.getLeft() );
    if( root.getRight() != null )
      inOrderTraverse( root.getRight() );
  }
  
  protected <T> void inOrderTraverse( BinaryTree<T> root )
  {

    if( root.getLeft() != null )
      inOrderTraverse( root.getLeft() );
    root.display();
    if( root.getRight() != null )
      inOrderTraverse( root.getRight() );
  }
  

  protected <T> void postOrderTraverse( BinaryTree<T> root )
  {
    if( root.getLeft() != null )
      inOrderTraverse( root.getLeft() );
    if( root.getRight() != null )
      inOrderTraverse( root.getRight() );
    root.display();
  }
}
